/*子应用*/
const express = require("express");

const query = require("../pool");

// const vertify = require("../modules/token");

const product = express.Router();
//获取到头像地址
product.get("/head_portrait", async (req, res) => {
  let obj = req.query;
 //console.log(obj.uname)
 //console.log("41564646646666")
  let result = await query(
    `select user_icon from cake_user where uname="${obj.uname}" ; `
  );
//console.log(result)
  if (result.length == 0) {
    res.send({ code: 0, msg: "没有查询成功" });
  } else {
    res.send({ code: 1, msg: "查询成功", data: result });
  }
});

// 存放评论的记录
product.post("/deposit", async (req, res) => {
  let obj = req.body;
  //获取到商品的名称
  let trade_name=obj.trade_name;
  //用户输入的内容
  let comment_content=obj.comment_content;
  //获取到的发布时间
  let time=obj.time;
  //获取到发布人的用户名
  let uname=obj.uname;
  //获取到发布人图片
  let base=obj.base;
  let head_portrait=obj.head_portrait
  // console.log(obj.trade_name)
  // console.log(obj.comment_content)
  // console.log(obj.time)
  // console.log(obj.uname)
  // console.log(obj.base)
  let result = await query(
    `insert into cake_review(trade_name,comment_content,time,uname,base,head_portrait) values('${trade_name}','${comment_content}','${time}','${uname}','${base}','${head_portrait}');`
  );
  if (result.length == 0) {
    res.send({ code: 0, msg: "没有添加成功" });
  } else {
    res.send({ code: 1, msg: "添加成功", data: result });
  }
});

//暴露
module.exports = product;
